/*
* $Id: RefObject.h 143 2010-09-09 19:55:18Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
#ifndef _REF_OBJECT_H_
#define _REF_OBJECT_H_

template<class T>
class CRefObject
{
	T* m_pObject;
public:
	CRefObject();
	~CRefObject();
	T* GetObject();
protected:
	CRefObject(const CRefObject<T>& pObject);
	T* Clone();
};

template<class T>
CRefObject<T>::~CRefObject(){
	if(m_pObject)
		delete m_pObject;
}

template<class T>
T* CRefObject<T>::GetObject(){
	if(!m_pObject)
		m_pObject = new T;
	return m_pObject;
}

template<class T>
CRefObject<T>::CRefObject(const CRefObject<T>& pObject){
	m_pObject = pObject.Clone();
}

template<class T>
CRefObject<T>::CRefObject()
 : m_pObject(NULL){}

#endif/*_REF_OBJECT_H_*/